<template>
	<view class="page container">
		<!-- 		<z-paging :refresher-enabled="false" :auto-full-height="false" :default-page-size="15" ref="pagingRef"
			v-model="dataList" @query="queryList" :paging-style="{ 'background-color': 'transparent' }"> -->

		<view class="h-28"></view>
		<u-tabs lineColor="#E61E1E" inactive-color="#666" :bar-style="barStyle" :list="list" :is-scroll="false"
			:current="current" @change="change"></u-tabs>

		<view class="list ">
			<!--  -->
			<navigator hover-class="none" :url="'/pages/orderDetail/index?id='+item.orderNum"
				class="item bgc-fff pad-28 flex-between-center" v-for="(item, index) in dataList" :key="index">
				<image :src="$config.domain+item.images" mode="aspectFit"></image>
				<view class="texts">
					<view class="flex-between-center">
						<view class="flex-center-center  fs-28 ">
							{{item.title}}

						</view>
					</view>
					<view class="fs-32 mt-16" style="color: #D61F1F;">
						{{item.point}}积分 <text class="fs-24 ml-10" style="color: #D61F1F;"> ¥{{item.amount}}元</text>
					</view>
					<view class="flex-between-center" style="justify-content: flex-end">
						<view v-if="current==1" class="paybtn mt-12" @click="pay(item)">
							未付款
						</view>
						<view v-if="current==0" class="paybtn mt-12"
							style="background-color: rgba(230,30,30,0.1) ;color: #E61E1E;">
							已付款
						</view>
					</view>

				</view>


				<!-- <view class="detail-btn w-124 h-60 br-12 flex-center-center">详情</view> -->
			</navigator>
			<emptydata v-if="dataList.length==0"></emptydata>
		</view>

	</view>
</template>

<script>
	import ScoreScreen from "@/components/ScoreScreen/index.vue";
	import LandMap from "@/components/LandMap.vue";
	import {
		paidList,
		unPaidList,
		goPay,
		getOpenId
	} from "@/services/home.js";
	export default {
		components: {
			ScoreScreen,
			LandMap,
		},
		data() {
			return {
				overlay_show: false,
				viewType: "list",
				dataList: [],
				params: {
					title: "",
					lat: "",
					lng: "",
				},
				selectedValues: {},
				list: [{
					name: '已付款'
				}, {
					name: '未付款'
				}, ],
				current: 0,
				openId: "",
				barStyle: {
					background: '#E61E1E'
				}

			};
		},
		onLoad() {
			//获取当前经纬度
			console.log(this.n)
			getOpenId({
				userId: uni.getStorageSync('userId')
			}).then(res => {
				console.log(res)
				this.openId = res.openid
			})
			// this.$refs.pagingRef?.reload();
			this.queryList()

		},
		onShow() {

		},

		methods: {
			change(e) {
				console.log(e)
				this.current = e.index;
				this.queryList()
			},
			handleMarkerClick(item) {
				this.$utils.to(`/pages/scoreDetail/index?id=${item.id}`);
			},
			handleSearch() {
				this.$refs.pagingRef?.reload();
			},
			queryList() {
				if (this.current == 0) {
					paidList({
						userId: uni.getStorageSync('userId')
					}).then(res => {
						console.log(res)
						this.dataList = res.data
					})
				} else {
					unPaidList({
						userId: uni.getStorageSync('userId')
					}).then(res => {
						console.log(res)
						this.dataList = res.data
					})
				}



			},

			pay(item) {
				uni.showLoading({
					title: '支付中'
				})
				goPay({
					openid: this.openId,
					amount: item.amount,
					orderNum: item.orderNum,
				}).then(res => {
					uni.requestPayment({
						provider: "wxpay",
						...res.data.config,
						success: function(res) {
							uni.hideLoading()
							console.log(res)
							uni.showToast({
								title: '支付成功',
								icon: 'none'
							})
							this.queryList()
						},
						fail: function(err) {
							uni.hideLoading()
							console.log(err)
							uni.showToast({
								title: '用户取消支付',
								icon: 'none'
							})
							this.queryList()

						},


					})
				})

			}
		},
	};
</script>

<style lang="scss" scoped>
	.filter-container {
		display: flex;
		width: 100%;
		background-color: #fff;
		position: relative;
		z-index: 100;
	}

	.filter-tab {
		flex: 1;
		display: flex;
		align-items: center;
		justify-content: center;
		padding: 12px 0;

		.arrow {
			font-size: 12px;
			margin-left: 4px;
			transition: transform 0.3s;
			color: #999;

			&.arrow-up {
				transform: rotate(180deg);
			}
		}
	}

	.page {
		background-color: #EFEFEF;

		.page-top {
			padding-bottom: 28rpx;

			.search-box {
				position: relative;
				z-index: 999;
			}
		}

		.filter-wrapper {
			position: relative;
			z-index: 100;
		}

		.list {
			// display: flex;
			// flex-wrap: wrap;
			// justify-content: space-between;
			padding: 0 20rpx;
			margin-top: 20rpx;

			.item {
				display: flex;
				align-items: center;
				position: relative;
				// flex-direction: column;
				width: 100%;
				margin-bottom: 32rpx;
				box-sizing: border-box;
				border-radius: 16rpx;

				image {
					width: 240rpx;
					height: 240rpx;
				}

				.detail-btn {
					position: absolute;
					right: 28rpx;
					bottom: 28rpx;
					font-size: 24rpx;
					font-weight: 500;
					color: #fff;
					background-color: $theme_color;
				}

				.texts {
					display: flex;
					flex-direction: column;
					justify-content: space-between;
					flex: 1;
					// width: 100%;
					// margin-top: 16rpx;
					// height: 216rpx;
					// margin-left: 24rpx;

					&>view {
						font-size: 28rpx;

						&>text:first-child {
							color: #677585;
						}
					}
				}
			}
		}
	}

	.tabs {
		font-weight: 400;
		font-size: 28rpx;
		margin: 30rpx;
		color: #3C3C3C;

		.on {
			font-weight: 700;
			font-size: 28rpx;
			color: #E61E1E;
		}
	}

	.add {
		margin: 60rpx auto;
		width: 690rpx;
		height: 90rpx;
		background: #CC0000;
		border-radius: 8rpx 8rpx 8rpx 8rpx;
		color: #fff;
		text-align: center;
		line-height: 90rpx;
	}

	.paybtn {
		width: 138rpx;
		height: 56rpx;
		background: #E61E1E;
		border-radius: 8rpx 8rpx 8rpx 8rpx;
		color: #fff;
		text-align: center;
		line-height: 56rpx;
	}
</style>